const Redis = require('ioredis')
const {errorHandler} = require("ioredis/built/redis/event_handler");
//const redis = new Redis('192.168.2.7:49153')
const testenv_redis = new Redis('192.168.4.81:6379')
//const testenv_redis = new Redis('code.qr4t.com:49153')


function Database() {
    this.testload=function (props) {
        return new Promise((resolve,reject) => {

            testenv_redis.hget(props.tablename+":"+props.keyword, props.fieldword).then(res=>{
                console.log("get from testload", res);
                if (res){
                    resolve(res)
                }else {
                    reject("load failed")
                    console.log("load failed");
                }
            })
            }
        )
    }
    this.testsave=function (props) {

        console.log('testsaveprops', props.tablename+":"+props.keyword, props.tablename+":"+props.fieldword,JSON.stringify(props));

        return new Promise((resolve,reject) => {
            testenv_redis.hset(props.tablename+":"+props.keyword, props.tablename+":"+props.fieldword,JSON.stringify(props)).then(res=>{
                console.log("set value to testsave", res);
                    resolve(res)

            })
            }
        )
    }
}


module.exports=Database